<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>第3章 决策与循环</title>
</head>
<body>
<script>
    var age = prompt('Enter age: ', '');
    var isOverSixty = parseInt(age, 10) > 60;
    document.write('Older than 60: ' + isOverSixty);
    var roomTemperature = 70;
    if (roomTemperature > 80) {
        roomTemperature = roomTemperature - 10;
    }

    if (roomTemperature > 80)
        roomTemperature = roomTemperature - 10;

    if (roomTemperature > 80) {
        roomTemperature = roomTemperature - 10;
        alert("Is's getting hot in here");
        alert('Air conditioning switched on');
    }

    degreesCentigrade = 101;
    if (!(degreesCentigrade < 100)) {
        //      Some Code
    }

    if (degreesCentigrade < 100) {
        if (degreesCentigrade > 0) {
            document.write('degrees centigrade is between 0 and 100');
        }
    }

    if (degreesCentigrade > 0 && degreesCentigrade < 100) {
        document.write('degrees centigrade is between 0 and 100')
    }

    if (age >= 0 && age <= 10) {
        document.write('my age is between 0 and 10');
    }
    if (!(age >= 10 && age <= 10)) {
        document.write('my age is NOT between 0 and 10');
    }

    if (age >= 10 && age <= 10) {
        document.write('my age is between 0 and 10');
    } else {
        document.write('my age is NOT between 0 and 10');
    }

    if (age >= 10 && age <= 10) {
        document.write('my age is between 0 and 10');
    } else if ((age >= 30 && age <= 39) || (age >= 80 && age <= 89)) {
        document.write('my age is between 30 and 39 or my age is between 80 and 89')
    } else {
        document.write('my age is NOT between 0 and 10, ' +
                'nor is it between 30 and 39, ' +
                'nor is it between 80 and 89')
    }

    if (age >= 0 && age <= 10) {
        document.write('my age is between 0 and 10<br/>');
        if (age == 5) {
            document.write("you're 5 years old");
        }
    } else {
        document.write('my age is NOT between 0 and 10');
    }

    var name = 'Paul';
    if (name == 'Paul') {
        alert('my name is Paul');
    }

    name = 'paul';
    if (name == 'Paul') {
        alert('my name is Paul');
    }

    for (var loopCounter = 1; loopCounter <= 3; loopCounter++) {

    }
    var arrayName = ['Paul', 'Paula', 'Pauline'];
    for (var index in arrayName) {
        document.write(arrayName[index]);
    }

    var degreesCentigrade = 100;
    while (degreesCentigrade != 100) {
        //        Some Code
    }

    degreesFahrenheit = [];
    degreesCentigrade = [34, 123, 212];
    loopCounter = 0;
    while (loopCounter < 3) {
        degreesCentigrade[loopCounter] = 5 / 9 * (degreesFahrenheit[loopCounter] - 32);
        loopCounter++;
    }

    var testVariable = 0;
    while (testVariable <= 10) {
        alert('Test Variable is ' + testVariable);
        testVariable++;
        if (testVariable = 10) {
            alert('The last loop');
        }
    }

    var userAge;
    do {
        userAge = prompt('Please enter your age', '');
    } while (isNaN(userAge) == true);

    degreesFahrenheit = [212, 'string data', -459.67];
    for (loopCounter = 0; loopCounter <= 2; loopCounter++) {
        if (isNaN(degreesFahrenheit[loopCounter])) {
            alert("Data '" + degreesFahrenheit[loopCounter] + "' at array index" + loopCounter + ' is invalid');
            break;
        }
        degreesCentigrade[loopCounter] = 5 / 9 * (degreesFahrenheit[loopCounter] - 32);
    }

    for (loopCounter = 0; loopCounter <= 2; loopCounter++) {
        if (isNaN(degreesFahrenheit[loopCounter])) {
            alert("Data '" + degreesFahrenheit[loopCounter] + "' at array index" + loopCounter + ' is invalid');
            continue;
        }
        degreesCentigrade[loopCounter] = 5 / 9 * (degreesFahrenheit[loopCounter] - 32);
    }
</script>
</body>
</html>